// 生成uuid
const generateUUID = () => {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(
    /[xy]/g,
    function (c) {
      let r = (Math.random() * 16) | 0,
        v = c == 'x' ? r : (r & 0x3) | 0x8;
      return v.toString(16);
    }
  );
}

// 数据分页
const dataPaging = (data, page = 0, pageSize = 0) => {
  if (page == 0 || pageSize == 0) return data;
  let length = data.length;
  let newArr = []
  let itemArr = []
  for (let i = 0; i <= length; i++) {
    let a = Math.floor((i - 1) / pageSize)
    let b = Math.floor(i / pageSize)
    if ((i > 0 && a !== b) || i === length) {
      newArr.push(itemArr)
      itemArr = []
    }
    itemArr.push(data[i])
  }
  return newArr[page - 1]
}
exports.generateUUID = generateUUID
exports.dataPaging = dataPaging